package org.jsola.hr.common;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jsola.common.BeanKit;
import org.jsola.common.ClassKit;
import org.jsola.common.SafeKit;
import org.jsola.exception.ParamException;
import org.jsola.hr.constant.*;
import org.jsola.hr.dto.EmpInfoUpdateDTO;
import org.jsola.hr.entity.*;
import org.jsola.hr.query.ChannelQuery;
import org.jsola.hr.service.IChannelService;
import org.jsola.hr.service.IDepInfoService;
import org.jsola.hr.service.IPositionInfoService;
import org.jsola.hr.vo.*;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author JanusMix
 */
@Slf4j
public class EmpFieldModuleCodeKit {



    @Data
    private static class ModuleCode {
        private String enName;
        private String zhName;
        private Boolean supportAdditional;
        private Boolean supportNecessary;
        private Integer sort;

        /**
         * 模块信息
         *
         * @param enName            模块英文名
         * @param zhName            模块中文名
         * @param supportAdditional 支持自定义字段
         * @param supportNecessary  必填校验(字段是多条还是单个)
         * @param sort              排序
         */
        public ModuleCode(String enName, String zhName, Boolean supportAdditional, Boolean supportNecessary, Integer sort) {
            this.enName = enName;
            this.zhName = zhName;
            this.supportAdditional = supportAdditional;
            this.supportNecessary = supportNecessary;
            this.sort = sort;
        }
    }

    /**
     * 所有模块枚举
     */
    private static final List<ModuleCode> ALL_MODULE_CODE_LIST = new ArrayList<>();

    /**
     * 个人信息模块枚举
     */
    private static final List<String> PERSONAL_INFO_MODULE_CODE_LIST = new ArrayList<>();

    /**
     * 社保相关模块枚举
     */
    private static final List<String> SOC_INFO_MODULE_CODE_LIST = new ArrayList<>();

    /**
     * 在职信息相关模块枚举
     */
    private static final List<String> ON_JOB_INFO_MODULE_CODE_LIST = new ArrayList<>();

    /**
     * 附件相关模块枚举
     */
    private static final List<String> ATTACH_MODULE_CODE_LIST = new ArrayList<>();

    static {
        ALL_MODULE_CODE_LIST.add(new ModuleCode("basic", "基本信息", true, false, 1));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("contact", "联系信息", true, false, 2));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("empFamily", "家庭成员", false, true, 3));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("empContacts", "紧急联系人", false, true, 4));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("empEducation", "教育经历", false, true, 5));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("empWork", "工作经历", false, true, 6));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("empTrain", "培训经历", false, true, 7));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("empIdCard", "身份信息", false, false, 8));

        ALL_MODULE_CODE_LIST.add(new ModuleCode("empState", "员工状态", true, false, 101));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("onJob", "在职信息", true, false, 102));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("file", "档案信息", true, false, 103));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("rewardsPunishments", "奖惩记录", false, true, 104));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("retire", "退休信息", true, false, 105));


        ALL_MODULE_CODE_LIST.add(new ModuleCode("bank", "工资卡信息", false, false, 201));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("socAndPf", "社保公积金信息", false, false, 202));

        ALL_MODULE_CODE_LIST.add(new ModuleCode("annex", "员工基本资料", true, false, 301));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("archive", "员工档案资料", true, false, 302));
        ALL_MODULE_CODE_LIST.add(new ModuleCode("leaveOffice", "员工离职资料", true, false, 303));

        //员工基本信息
        PERSONAL_INFO_MODULE_CODE_LIST.add("basic");
        //员工教育经历
        PERSONAL_INFO_MODULE_CODE_LIST.add("empEducation");
        //员工联系人
        PERSONAL_INFO_MODULE_CODE_LIST.add("contact");
        //员工紧急联系人
        PERSONAL_INFO_MODULE_CODE_LIST.add("empContacts");
        //员工家庭成员
        PERSONAL_INFO_MODULE_CODE_LIST.add("empFamily");
        //员工培训记录
        PERSONAL_INFO_MODULE_CODE_LIST.add("empTrain");
        //员工工作经历
        PERSONAL_INFO_MODULE_CODE_LIST.add("empWork");
        //员工身份信息
        PERSONAL_INFO_MODULE_CODE_LIST.add("empIdCard");

        //员工工资卡信息
        SOC_INFO_MODULE_CODE_LIST.add("bank");
        SOC_INFO_MODULE_CODE_LIST.add("socAndPf");

        //员工基本资料附件
        ATTACH_MODULE_CODE_LIST.add("annex");
        //员工档案资料附件
        ATTACH_MODULE_CODE_LIST.add("archive");
        //员工离职资料附件
        ATTACH_MODULE_CODE_LIST.add("leaveOffice");

        // 在职信息
        ON_JOB_INFO_MODULE_CODE_LIST.add("empState");
        ON_JOB_INFO_MODULE_CODE_LIST.add("onJob");
        ON_JOB_INFO_MODULE_CODE_LIST.add("file");
        ON_JOB_INFO_MODULE_CODE_LIST.add("rewardsPunishments");
        ON_JOB_INFO_MODULE_CODE_LIST.add("retire");
    }

    /**
     * 获取员工个人信息设置的模块
     *
     * @return list
     */
    public static List<String> getAllModuleCodeList() {
        return ALL_MODULE_CODE_LIST.stream().map(ModuleCode::getEnName).collect(Collectors.toList());
    }

    /**
     * 是否是员工个人信息设置模块的code
     *
     * @param moduleCode code
     * @return true or false
     */
    public static Boolean isModuleCodeInPersonalInfoList(String moduleCode) {
        return PERSONAL_INFO_MODULE_CODE_LIST.contains(moduleCode);
    }

    /**
     * 是否是员工社保信息设置模块的code
     *
     * @param moduleCode code
     * @return true or false
     */
    public static Boolean isModuleCodeInSocInfoList(String moduleCode) {
        return SOC_INFO_MODULE_CODE_LIST.contains(moduleCode);
    }

    /**
     * 是否是员工在职信息设置模块的code
     *
     * @param moduleCode code
     * @return true or false
     */
    public static Boolean isModuleCodeInOnJob(String moduleCode) {
        return ON_JOB_INFO_MODULE_CODE_LIST.contains(moduleCode);
    }

    /**
     * 是否是员工附件信息设置模块的code
     *
     * @param moduleCode code
     * @return true or false
     */
    public static Boolean isModuleCodeInAttachList(String moduleCode) {
        return ATTACH_MODULE_CODE_LIST.contains(moduleCode);
    }

    /**
     * 根据分类判断moduleCode
     *
     * @param type       类型，1个人信息设置，2工资社保设置，3材料附件设置
     * @param moduleCode code
     * @return true or false
     */
    public static Boolean isModuleTypeInTypeList(Integer type, String moduleCode) {
        if (type == null) {
            return Boolean.TRUE;
        }
        if (type == 1) {
            return isModuleCodeInPersonalInfoList(moduleCode);
        } else if (type == 2) {
            return isModuleCodeInSocInfoList(moduleCode);
        } else if (type == 3) {
            return isModuleCodeInAttachList(moduleCode);
        } else if (type == 4) {
            return isModuleCodeInOnJob(moduleCode);
        } else {
            log.error("模块类型有误：{}", type);
            throw new ParamException("模块类型有误");
        }
    }

    /**
     * 获取字段的顺序
     *
     * @param companyFieldInfoVO field对象
     * @return 排序值
     */
    public static int getModuleCodeSort(CompanyFieldInfoVO companyFieldInfoVO) {
        for (ModuleCode mc : ALL_MODULE_CODE_LIST) {
            if (mc.getEnName().equals(companyFieldInfoVO.getModuleCode())) {
                return mc.getSort();
            }
        }
        return 0;
    }

    /**
     * 获取moduleCode排序比较器
     *
     * @return Comparator
     */
    public static Comparator<CompanyFieldInfoVO> getModuleCodeComparator() {
        return Comparator.comparingInt(EmpFieldModuleCodeKit::getModuleCodeSort);
    }

    /**
     * 获取moduleCode是否支持自定义字段
     *
     * @param moduleCode code
     * @return true or false
     */
    public static Boolean getModuleCodeSupportAdditional(String moduleCode) {
        for (ModuleCode mc : ALL_MODULE_CODE_LIST) {
            if (mc.getEnName().equals(moduleCode)) {
                return mc.getSupportAdditional();
            }
        }
        return Boolean.FALSE;
    }

    /**
     * 获取moduleCode中文名
     *
     * @param moduleCode code
     * @return 中文名
     */
    public static String getModuleCodeZhName(String moduleCode) {
        for (ModuleCode mc : ALL_MODULE_CODE_LIST) {
            if (mc.getEnName().equals(moduleCode)) {
                return mc.getZhName();
            }
        }
        return "";
    }

    /**
     * 获取moduleCode是否支持必填校验
     *
     * @param moduleCode code
     * @return true or false
     */
    public static Boolean getModuleCodeSupportNecessary(String moduleCode) {
        for (ModuleCode mc : ALL_MODULE_CODE_LIST) {
            if (mc.getEnName().equals(moduleCode)) {
                return mc.getSupportNecessary();
            }
        }
        return Boolean.FALSE;
    }

    /**
     * 基本信息和联系方式必填
     *
     * @param moduleCode moduleCode
     * @return true or false
     */
    public static Boolean getModuleCodeNecessary(String moduleCode) {
        return "basic".equals(moduleCode) || "contact".equals(moduleCode);
    }

    /**
     * 将员工信息的值注入到字段列表的属性中
     *
     * @param fieldList 字段列表
     * @param empInfoVO 员工对象
     */
    public static Map<String, String> processEmpFieldList(List<CompanyNecessaryFieldVO> fieldList, EmpInfoVO empInfoVO) {
        Map<String, String> dataMap = new HashMap<>(16);
        if (empInfoVO == null) {
            return dataMap;
        }
        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
            String fieldCode = companyNecessaryFieldVO.getFieldCode();
            try {
                Object value = ClassKit.getValue(empInfoVO, fieldCode);
                dataMap.put(companyNecessaryFieldVO.getFieldCode(), SafeKit.getString(value));
            } catch (Exception e) {
                log.error("员工表未找到" + fieldCode + "字段!");
            }
        }
        return dataMap;
    }

    /**
     * 将员工信息的值注入到员工修改对象中
     *
     * @param data      字段列表
     * @param updateDTO 员工对象
     */
    public static void processEmpFieldList(Map<String, String> data, EmpInfoUpdateDTO updateDTO) {
        data.forEach((field, value) -> {
            try {
                //值转换为字段属性的类型
                Object convertValue = ClassKit.convert(value, ClassKit.getField(updateDTO.getClass(), field).getType());
                //然后再注入
                ClassKit.inject(updateDTO, field, convertValue);
            } catch (Exception e) {
                log.error("员工表未找到" + field + "字段!");
            }
        });
    }

    /**
     * 将一个实体列表的值返回到动态字段列表中
     *
     * @param fieldList  字段列表
     * @param entityList 实体列表
     * @return 数据list<map>
     */
    public static List<Map<String, String>> processContactFieldList(List<CompanyNecessaryFieldVO> fieldList, List<EmpContactsDO> entityList) {
        List<Map<String, String>> fieldObjectList = new ArrayList<>();
        for (EmpContactsDO entity : entityList) {
            Map<String, String> dataMap = new LinkedHashMap<>();
            dataMap.put("id", SafeKit.getString(entity.getId()));
            dealMapData(entity, dataMap, fieldList);
            fieldObjectList.add(dataMap);
        }
        return fieldObjectList;
    }

    /**
     * 将一个实体列表的值返回到动态字段列表中
     *
     * @param fieldList  字段列表
     * @param entityList 实体列表
     * @return 数据list<map>
     */
    public static List<Map<String, String>> processEducationFieldList(List<CompanyNecessaryFieldVO> fieldList, List<EmpEducationDO> entityList) {
        List<Map<String, String>> fieldObjectList = new ArrayList<>();
        for (EmpEducationDO entity : entityList) {
            Map<String, String> dataMap = new LinkedHashMap<>();
            dataMap.put("id", SafeKit.getString(entity.getId()));
            dealMapData(entity, dataMap, fieldList);
            fieldObjectList.add(dataMap);
        }
        return fieldObjectList;
    }

    /**
     * 将一个实体列表的值返回到动态字段列表中
     *
     * @param fieldList  字段列表
     * @param entityList 实体列表
     * @return 数据list<map>
     */
    public static List<Map<String, String>> processFamilyFieldList(List<CompanyNecessaryFieldVO> fieldList, List<EmpFamilyDO> entityList) {
        List<Map<String, String>> fieldObjectList = new ArrayList<>();
        for (EmpFamilyDO entity : entityList) {
            Map<String, String> dataMap = new LinkedHashMap<>();
            dataMap.put("id", SafeKit.getString(entity.getId()));
            dealMapData(entity, dataMap, fieldList);
            fieldObjectList.add(dataMap);
        }
        return fieldObjectList;
    }

    /**
     * 将一个实体列表的值返回到动态字段列表中
     *
     * @param fieldList  字段列表
     * @param entityList 实体列表
     * @return 数据list<map>
     */
    public static List<Map<String, String>> processTrainFieldList(List<CompanyNecessaryFieldVO> fieldList, List<EmpTrainDO> entityList) {
        List<Map<String, String>> fieldObjectList = new ArrayList<>();
        for (EmpTrainDO entity : entityList) {
            Map<String, String> dataMap = new LinkedHashMap<>();
            dataMap.put("id", SafeKit.getString(entity.getId()));
            dealMapData(entity, dataMap, fieldList);
            fieldObjectList.add(dataMap);
        }
        return fieldObjectList;
    }

    /**
     * 将一个实体列表的值返回到动态字段列表中
     *
     * @param fieldList  字段列表
     * @param entityList 实体列表
     * @return 数据list<map>
     */
    public static List<Map<String, String>> processWorkFieldList(List<CompanyNecessaryFieldVO> fieldList, List<EmpWorkDO> entityList) {
        List<Map<String, String>> fieldObjectList = new ArrayList<>();
        for (EmpWorkDO entity : entityList) {
            Map<String, String> dataMap = new LinkedHashMap<>();
            dataMap.put("id", SafeKit.getString(entity.getId()));
            dealMapData(entity, dataMap, fieldList);
            fieldObjectList.add(dataMap);
        }
        return fieldObjectList;
    }

    public static List<Map<String, String>> processRewardPunishList(List<CompanyNecessaryFieldVO> fieldList,
                                                                    List<EmpRewardPunishDO> empRewardPunish) {
        List<Map<String, String>> fieldObjectList = new ArrayList<>();
        for (EmpRewardPunishDO entity : empRewardPunish) {
            Map<String, String> dataMap = new LinkedHashMap<>();
            dataMap.put("id", SafeKit.getString(entity.getId()));
            dealMapData(entity, dataMap, fieldList);
            fieldObjectList.add(dataMap);
        }
        return fieldObjectList;
    }

    private static void dealMapData(Object object, Map<String, String> dataMap, List<CompanyNecessaryFieldVO> fieldList) {
        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
            String fieldCode = companyNecessaryFieldVO.getFieldCode();
            try {
                Object value = ClassKit.getValue(object, fieldCode);
                dataMap.put(companyNecessaryFieldVO.getFieldCode(), SafeKit.getString(value));
            } catch (Exception e) {
                log.error("实体表未找到" + fieldCode + "字段!");
            }
        }
    }

    /**
     * 设置字段的下拉选项数组
     *
     * @param companyId  用工单位Id
     * @param fieldList  字段列表
     * @param moduleCode 模块code
     * @param siteId     站点Id
     */
    public static void setFieldDropDownArray(String companyId, List<CompanyNecessaryFieldVO> fieldList, String moduleCode, String siteId) {
        if (CollectionUtils.isEmpty(fieldList)) {
            return;
        }
        switch (moduleCode) {
            case "basic":
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    switch (companyNecessaryFieldVO.getFieldCode()) {
                        case "gender":
                            List<DropDownEnumVO> dropDownEnumList = new ArrayList<>();
                            Arrays.stream(GenderEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList);
                            break;
                        case "bloodGroup":
                            List<DropDownEnumVO> dropDownEnumList2 = new ArrayList<>();
                            Arrays.stream(BloodGroupEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList2.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList2);
                            break;
                        case "politicalStatus":
                            List<DropDownEnumVO> dropDownEnumList3 = new ArrayList<>();
                            Arrays.stream(EmpPoliticalStatus.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList3.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList3);
                            break;
                        case "nation":
                            String a = "汉族,满族,蒙古族,回族,藏族,维吾尔族,苗族,彝族,壮族,布依族,侗族,瑶族,白族,土家族,哈尼族,哈萨克族,傣族,黎族,傈僳族,佤族,畲族,高山族,拉祜族,水族,东乡族,纳西族,景颇族,柯尔克孜族,土族,达斡尔族,仫佬族,羌族,布朗族,撒拉族,毛南族,仡佬族,锡伯族,阿昌族,普米族,朝鲜族,塔吉克族,怒族,乌孜别克族,俄罗斯族,鄂温克族,德昂族,保安族,裕固族,京族,塔塔尔族,独龙族,鄂伦春族,赫哲族,门巴族,珞巴族,基诺族";
                            //民族
                            List<DropDownEnumVO> dropDownEnumList4 = new ArrayList<>();
                            Arrays.stream(a.split(",")).forEach(b -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(b);
                                dropDownEnumVO.setLabel(b);
                                dropDownEnumList4.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList4);
                            break;
                        case "regType":
                            List<DropDownEnumVO> dropDownEnumList5 = new ArrayList<>();
                            Arrays.stream(RegTypeEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList5.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList5);
                            break;
                        case "birthStatus":
                            List<DropDownEnumVO> dropDownEnumList6 = new ArrayList<>();
                            Arrays.stream(EmpBirthStatus.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList6.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList6);
                            break;
                        case "maritalStatus":
                            List<DropDownEnumVO> dropDownEnumList7 = new ArrayList<>();
                            Arrays.stream(EmpMaritalStatus.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList7.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList7);
                            break;
                        default:
                            break;
                    }
                }
                break;
            case "empState":
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    switch (companyNecessaryFieldVO.getFieldCode()) {
                        case "postType":
                            //员工状态取数据库配置，不使用枚举类
//                            List<DropDownEnumVO> dropDownEnumList1 = new ArrayList<>();
//                            Arrays.stream(PostType.values()).forEach(genderEnum -> {
//                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
//                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
//                                dropDownEnumVO.setLabel(genderEnum.getDesc());
//                                dropDownEnumList1.add(dropDownEnumVO);
//                            });
//                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList1);
//                            break;
                        case "formalType":
                            List<DropDownEnumVO> dropDownEnumList2 = new ArrayList<>();
                            Arrays.stream(FormalTypeEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList2.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList2);
                            break;
                        case "channelId":
                            List<DropDownEnumVO> dropDownEnumList3 = new ArrayList<>();
                            IChannelService channelService = BeanKit.getBean(IChannelService.class);
                            List<ChannelListVO> channelListVOList = channelService.select(new ChannelQuery(), siteId);
                            for (ChannelListVO channelListVO : channelListVOList) {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(channelListVO.getId());
                                dropDownEnumVO.setLabel(channelListVO.getName());
                                dropDownEnumList3.add(dropDownEnumVO);
                            }
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList3);
                            break;
                        default:
                            break;
                    }
                }
            case "onJob":
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    switch (companyNecessaryFieldVO.getFieldCode()) {
                        case "preJoinDep":
                            List<DropDownEnumVO> dropDownEnumList1 = new ArrayList<>();
                            IDepInfoService depInfoService = BeanKit.getBean(IDepInfoService.class);
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList1);
                            break;
                        case "preJoinPosition":
                            List<DropDownEnumVO> dropDownEnumList2 = new ArrayList<>();
                            IPositionInfoService positionInfoService = BeanKit.getBean(IPositionInfoService.class);
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList2);
                            break;
                        case "sourceType":
                            List<DropDownEnumVO> dropDownEnumList3 = new ArrayList<>();
                            Arrays.stream(EmpSourceTypeEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList3.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList3);
                            break;
                        default:
                            break;
                    }
                }
            case "retire":
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    switch (companyNecessaryFieldVO.getFieldCode()) {
                        case "retirementStatus":
                            List<DropDownEnumVO> dropDownEnumList8 = new ArrayList<>();
                            DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                            dropDownEnumVO.setValue("true");
                            dropDownEnumVO.setLabel("是");
                            dropDownEnumList8.add(dropDownEnumVO);

                            DropDownEnumVO dropDownEnumVO1 = new DropDownEnumVO();
                            dropDownEnumVO1.setValue("false");
                            dropDownEnumVO1.setLabel("否");
                            dropDownEnumList8.add(dropDownEnumVO1);

                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList8);
                            break;
                        default:
                            break;
                    }
                }
            case "socAndPf":
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    switch (companyNecessaryFieldVO.getFieldCode()) {
                        case "isFirstPf":
                        case "isFirstSoc":
                            List<DropDownEnumVO> dropDownEnumList8 = new ArrayList<>();
                            DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                            dropDownEnumVO.setValue("true");
                            dropDownEnumVO.setLabel("是");
                            dropDownEnumList8.add(dropDownEnumVO);

                            DropDownEnumVO dropDownEnumVO1 = new DropDownEnumVO();
                            dropDownEnumVO1.setValue("false");
                            dropDownEnumVO1.setLabel("否");
                            dropDownEnumList8.add(dropDownEnumVO1);

                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList8);
                            break;

                        default:
                            break;
                    }
                }
                break;
            case "empEducation":
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    switch (companyNecessaryFieldVO.getFieldCode()) {
                        case "degreeType":
                            List<DropDownEnumVO> dropDownEnumList8 = new ArrayList<>();
                            Arrays.stream(EmpDegreeType.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList8.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList8);
                            break;
                        case "education":
                            List<DropDownEnumVO> dropDownEnumList9 = new ArrayList<>();
                            Arrays.stream(EducationLevelEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList9.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList9);
                            break;
                        case "teaMethods":
                            List<DropDownEnumVO> dropDownEnumList10 = new ArrayList<>();
                            Arrays.stream(TeachMethod.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList10.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList10);
                            break;
                        default:
                            break;
                    }
                }
                break;
            case "rewardsPunishments":
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    switch (companyNecessaryFieldVO.getFieldCode()) {
                        //奖励、惩罚
                        case "rewardPunish":
                            List<DropDownEnumVO> dropDownEnumList11 = new ArrayList<>();
                            Arrays.stream(RewardPunishEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList11.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList11);
                            break;
                        //奖励类别
                        case "rewardType":
                            List<DropDownEnumVO> dropDownEnumList13 = new ArrayList<>();
                            Arrays.stream(RewardTypeEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList13.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList13);
                            break;
                        //惩罚类别
                        case "punishType":
                            List<DropDownEnumVO> dropDownEnumList14 = new ArrayList<>();
                            Arrays.stream(PunishTypeEnum.values()).forEach(genderEnum -> {
                                DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
                                dropDownEnumVO.setValue(SafeKit.getString(genderEnum.getValue()));
                                dropDownEnumVO.setLabel(genderEnum.getDesc());
                                dropDownEnumList14.add(dropDownEnumVO);
                            });
                            companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList14);
                            break;
                        default:
                            break;
                    }
                }
                break;
            default:
                break;
        }
    }

    /**
     * 给字段列表设置概览显示的字段
     *
     * @param fieldList 字段列表
     */
    public static void setFieldGroupName(List<CompanyNecessaryFieldVO> fieldList) {
        if (CollectionUtils.isEmpty(fieldList)) {
            return;
        }
        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
            if ("empContacts".equals(companyNecessaryFieldVO.getModuleCode()) && "name".equals(companyNecessaryFieldVO.getFieldCode())) {
                companyNecessaryFieldVO.setGroupField(Boolean.TRUE);
            }
            if ("empEducation".equals(companyNecessaryFieldVO.getModuleCode()) && "graCollege".equals(companyNecessaryFieldVO.getFieldCode())) {
                companyNecessaryFieldVO.setGroupField(Boolean.TRUE);
            }
            if ("empFamily".equals(companyNecessaryFieldVO.getModuleCode()) && "name".equals(companyNecessaryFieldVO.getFieldCode())) {
                companyNecessaryFieldVO.setGroupField(Boolean.TRUE);
            }
            if ("empTrain".equals(companyNecessaryFieldVO.getModuleCode()) && "trainOrgName".equals(companyNecessaryFieldVO.getFieldCode())) {
                companyNecessaryFieldVO.setGroupField(Boolean.TRUE);
            }
            if ("empWork".equals(companyNecessaryFieldVO.getModuleCode()) && "company".equals(companyNecessaryFieldVO.getFieldCode())) {
                companyNecessaryFieldVO.setGroupField(Boolean.TRUE);
            }
        }
    }

    /**
     * 校验字段长度
     *
     * @param fieldType 字段类型
     * @param fieldName 字段名称
     * @param content   字段内容
     */
    public static void checkFieldType(Integer fieldType, String fieldName, String content) {
        if (content == null) {
            return;
        }
        if (HrConstants.FIELD_TYPE_TEXT.equals(fieldType)) {
            if (content.length() > 50) {
                throw new ParamException("【" + fieldName + "】长度不能超过50");
            }
        } else if (HrConstants.FIELD_TYPE_TEXTAREA.equals(fieldType)) {
            if (content.length() > 200) {
                throw new ParamException("【" + fieldName + "】长度不能超过200");
            }
        }
    }

}
